
// this is a test for generate the dll for c# invoke.
// ref  https://www.cnblogs.com/chenxizhang/p/4760674.html
use std::thread::JoinHandle;
use std::thread;


#[no_mangle]
pub extern fn process() {
    let handles:Vec<JoinHandle<i32>> = (0..10).map(|_| {
        thread::spawn(|| {
            let mut x = 0;
            for _ in 0..5000000 {
                x += 1;
            }
            x
        })
    }).collect();

    // let mut handles = vec![];
    // for i in 0..10 {
    //     let handle = thread::spawn(|| {
    //         let mut x = 0;
    //         for _ in 0..5000000 {
    //             x += 1;
    //         }
    //         x
    //     });
    //     handles.push(handle);
    // }

    for h in handles {
        println!("Thread finished with count={}", h.join().map_err(|_|{ "Count not join a thread" }).unwrap());
    }

    println!("[Rust] done!");
}



// pub fn add(left: usize, right: usize) -> usize {
//     left + right
// }

// #[cfg(test)]
// mod tests {
//     use super::*;

//     #[test]
//     fn it_works() {
//         let result = add(2, 2);
//         assert_eq!(result, 4);
//     }
// }
